<!-- 子组件 ChildTable.vue 动态生成列表信息-->
<template>
  <div>
    <div class="selection-toolbar">
    <el-space>
        <span v-if="selectedRows.length > 0">
          已选中 {{ selectedRows.length }} 条记录
        </span>
        <span v-else class="muted-text">未选择任何记录</span>
        <el-button v-if="selectedRows.length > 0" type="primary" size="small" @click="handleBatchDelete">审核</el-button>
        <el-button v-if="selectedRows.length > 0" type="primary" size="small" @click="importSelect">导出</el-button>
        <el-button v-if="selectedRows.length > 0" type="primary" size="small" @click="exportSelected">导出</el-button>
        <el-button v-if="selectedRows.length > 0" type="danger" size="small" @click="handleBatchDelete">删除</el-button>
    </el-space>
  </div>

  <el-table :data="data" style="width: 1200px" @selection-change="handleSelectionChange" @select-all="handleSelectAll">
    <el-table-column type="selection" width="55" align="center"/>
    <!-- 动态列 -->
    <el-table-column 
      v-for="col in columns"
      :key="col.prop"
      :prop="col.prop"
      :label="col.label"
    />
    
    <!-- 固定操作列 -->
    <el-table-column label="操作" width="180">
      <template #default="{ row }">
        <el-button type="primary" @click="handleEdit(row)">修改</el-button>
        <el-button type="danger" @click="handleDelete(row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div class="demo-pagination-block">
    <div class="demonstration">修改页容量</div>
    <el-pagination
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[10, 20, 30, 40]"
      layout="sizes, prev, pager, next"
      :total="4"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { defineProps } from 'vue'

// 定义Props类型
interface TableColumn {
  prop: string
  label: string
  width?: number
}

// 声明接收的Props
const props = defineProps({
  columns: {
    type: Array as () => TableColumn[],
    required: true,
    validator: (cols: TableColumn[]) => 
      cols.every(c => c.prop && c.label)
  },
  data: {
    type: Array,
    default: () => []
  }
})

// 事件处理
const handleEdit = (row: any) => {
  console.log('Edit row:', row)
}

const handleDelete = (row: any) => {
  console.log('Delete row:', row)
}
const currentPage = ref(5)
const pageSize = ref(10)
// 已选数据（保持原有代码）
const selectedRows = ref<any[]>([])

// 新增批量删除方法
const handleBatchDelete = () => {
  
}
const importSelect = () =>{

}
const exportSelected = () =>{
  
}
// 全选事件处理
const handleSelectAll = (selection: any[]) => {
  selectedRows.value = selection
}

// 选择变化事件
const handleSelectionChange = (selection: any[]) => {
  selectedRows.value = selection
}

const handleClick = () => {
  console.log('click')
}
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`)
}
</script>